#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

#define rep(i,n) for (int i=0; i<n; i++)

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

#define MULT_TEST(x...) 

#define st first
#define fin second

#define les first
#define ind second

int _42;

int n;
pair< pair<int, int>, int> time[5050];
int k;
int cancel[5050];
int icont;

int main() {
	MULT_TEST(
		scanf("%d", &_42);

		while (_42--) {
	)

	scanf("%d", &n);

	rep(i,n) {
		scanf("%d %d", &time[i].les.st, &time[i].les.fin);
		time[i].ind=i+1;
	}

	sort(time, time+n);

	k=0;
	icont=0;

	rep(i,n) {
		icont=0;

		for (int j=1; j<n; j++) {
			if (i==j) continue;
			if (j-1==i) {
				if (j-2<0) continue;
				if (time[j].les.st<time[j-2].les.fin) icont++;
			}
			else {
				if (time[j].les.st<time[j-1].les.fin) icont++;
			}
		}

		PRINT("icont for %d: %d\n", i+1, icont);

		if (!icont) {
			cancel[k++]=time[i].ind;
		}
	}	

	printf("%d\n", k);
	sort(cancel, cancel+k);

	rep(i,k) printf("%d ", cancel[i]);
	if (k>0) printf("\n");

	MULT_TEST( } )
	
	return 0;
}
